﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//WB Added
using System.Xml;

using System.IO;

namespace DictionaryTranslate.Installer
{
    public partial class DictionaryTranslateInstaller : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string configFilePath = Server.MapPath("~/config/cws_dictionaryTranslate.config");

            //Check if XML file exists
            if (!File.Exists(configFilePath))
            {
                //Throw error saying file does not exist (it should though from package install)

                return;
            }
            else
            {
                //Load the XML doc
                XmlDocument configFile = new XmlDocument();
                configFile.Load(configFilePath);

                //Select the root node <dictionaryTranslate>
                XmlNode rootNode = configFile.DocumentElement;

                //<appID key="C1CC44B600CAAABE93074D68F34F51F6EA9697DF" />
                //appID = rootNode.SelectSingleNode("appID").Attributes.GetNamedItem("key").Value;

                rootNode.SelectSingleNode("appID").Attributes.GetNamedItem("key").Value = txtAppIDKey.Text;
                
                //Save the changes
                configFile.Save(configFilePath);

                //Hide setup panel
                pnlInstall.Visible = false;

                //Show done panel
                pnlDone.Visible = true;

            }
        }
    }
}